package com.twu.biblioteca;


import java.util.ArrayList;

public class Biblioteca {
    public ArrayList<Book> books;
    private Messages messages;
    private ArrayList<User> users;

    public Biblioteca(ArrayList<Book> books, Messages messages, ArrayList<User> users){
        this.books = books;
        this.messages = messages;
        this.users = users;
    }

    public String listAllBooks() {
        String newLine = System.getProperty("line.separator");
        String strAllBooks = "== All Books ==" + newLine;
        strAllBooks = "ID\tTitle\tAvaible" + newLine;
        for (Book item : books) {
            String avaible = "";
            if (item.available){
                avaible = "Yes";
            } else {
                avaible = "No";
            }
            strAllBooks += "ID" + item.id + " - " + item.title + " - " + avaible + newLine;
        }
        return strAllBooks;
    }

    public Book reserveBook(Book book){
        if (book.available){
            book.available = false;
            System.out.println(messages.getreservedSuccessfully());
        }
        else {
            System.out.println(messages.getbookNotAvailable());
        }
        return book;
    }

    public String detailsMembership(User user){
        if (user.isLogged()){
            String detailsUser = "";
            String newLine = System.getProperty("line.separator");
            detailsUser += "Name: " + user.getName() + newLine;
            detailsUser += "Email: " + user.getEmail() + newLine;
            detailsUser += "Phone: " + user.getPhone() + newLine;

            return detailsUser;

        } else {
            return messages.getmembershipDetails();
        }
    }

}
